var React = require('react-native');
var {AsyncStorage} = React;



/**
 * 获取省市区数据
 */
exports.fetchRegionData = () => {
  return new Promise((resolve, reject) => {
    AsyncStorage.getItem('d2p@china-region', (err, result) => {
      if (__DEV__) {
        console.log('获取d2p@china-region的缓存');
      }
      if (result) {
        if (__DEV__) {
          console.log('get d2p@china-region successfully.');
        }
        resolve(JSON.parse(result));
      } else {
        fetch('http://pic.ofcard.com/themes/common/region/China_Region_Last.js')
        .then((res) => res._bodyText)
        .then((res) => {
          //巧妙的转换
          eval(res);
          AsyncStorage.setItem('d2p@china-region', JSON.stringify(CHINA_REGION));
          resolve(CHINA_REGION);
        })
        .catch((err) => reject(err))
        .done();
      }
    });
  });
};
